<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>

</head>
<body>


<script type="text/javascript">
  let data = {name: '张三', age: 18};
  var obs = new Observer(data);
  const vm = {};
  vm._data = data = obs;

  function Observer(val) {
    var keys = Object.keys(val);
    keys.forEach((k) => {
      Object.defineProperty(this, k, {
        get() {
          return val[k];
        },
        set(v) {
          console.log(k+'发生改变,更新虚拟DOM,开始工作...')
          val[k] = v;
        }
      })
    })
  }
</script>
</body>
</html>
